package com.ulook.lookplanet.controller;

import com.ulook.lookplanet.bean.TCommunity;
import com.ulook.lookplanet.bean.TTopic;
import com.ulook.lookplanet.common.ExceptionCode;
import com.ulook.lookplanet.common.JsonResult;
import com.ulook.lookplanet.service.CommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 描述：
 *
 * @author L1998
 * @date 2021/4/20
 */
@RestController
@RequestMapping("/community")
public class CommunityController {

    @Autowired
    private CommunityService service;

    /**
     * 查询小组列表
     */
    @PostMapping("/getCommunityList")
    public JsonResult<List<TCommunity>> getCommunityList(HttpServletRequest request){
        List<TCommunity> communities = service.getCommunityList();
        if(communities.size() == 0){
            return new JsonResult<>(ExceptionCode.NO_DATA, "未查询到小组");
        }
        return new JsonResult<>(communities);
    }

    /**
     * 查询话题列表
     */
    @PostMapping("/getTopicsForComuId")
    public JsonResult<List<TTopic>> getTopicsForComuId(HttpServletRequest request){
        String comuId = request.getParameter("comuId");
        if (comuId == null || "".equals(comuId)){
            return new JsonResult<>(ExceptionCode.NULL_PARAM, "参数为空");
        }
        List<TTopic> topics = service.getTopicsForComuId(comuId);
        if(topics.size() == 0){
            return new JsonResult<>(ExceptionCode.NO_DATA, "未查询到话题");
        }
        return new JsonResult<>(topics);
    }
}
